﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.DAL;
using WXYW.BLL;

namespace WXYW
{
    public partial class Quatation : System.Web.UI.Page
    {
        public ApplicationQuatationFormModel model;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitialPage();
            }
        }

        private void InitialPage()
        {
            ApplicationProductService service = new ApplicationProductService();
            model = service.GetConfirmQuatationFormProductsForQuatation(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            runningNumberLabel.Text = model.RunningNumber;
            nameLabel.Text = model.Client.FullName;
            connectPersonLabel.Text = model.Client.ContactPerson;
            faxLabel.Text = model.Client.UserFax;
            totalPriceLabel.Text = model.TotalPrices.ToString();
            receivetimeLabel.Text = model.ReceiveTime.ToString("yyyy-MM-dd");
            quatationtimeLabel.Text = model.QuatationTime.ToString("yyyy-MM-dd");
            userphoneLabel.Text = model.ContactPhone;
            productGridView.DataSource = model.Products;
            productGridView.DataBind();

            SpecialServiceService specialServiceService = new SpecialServiceService();
            SpecialServiceForm specialServiceForm = specialServiceService.GetSpecialServiceByApplicationFormID(Convert.ToInt64(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            if (specialServiceForm != null)
            {
                string status = "";
                switch (specialServiceForm.Status)
                {
                    case "1":
                        status = "特服申请-待处理";
                        break;
                    case "2":
                        status = "特服申请-待填";
                        break;
                    case "3":
                        status = "等待初审人签字";
                        break;
                    case "4":
                        status = "等待终审人签字";
                        break;
                    case "5":
                        status = "等待加签人签字";
                        break;
                    case "6":
                        status = "审批完成";
                        break;
                }
                tfLnk.Text = string.Format("特服申请单号：{0}, 当前状态：{1}", specialServiceForm.ApplicationCode, status);
                tfLnk.NavigateUrl = string.Format("TFSQDetail.aspx?{0}={1}", Constants.QUERYSTR_APPLICATION_ID, specialServiceForm.ID);
            }
        }

        protected void productGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                ((Label)e.Row.FindControl("IDLbl")).Text = (e.Row.RowIndex + 1).ToString();
            }
        }
    }
}
